<?
class InputArray extends Input
{
	var $aInput;
	var $bHidden = false;
	var $bAutoRefresh  = false;
	var $cSeparator = '|';

	function getLabelsArray( $cPrefix )
	{
		$aLabel = array();
		foreach( $this->aInput as $cField => $oField )
		{
			$aLabel[str_replace(' ' ,'', $oField->getLabel())] = $cPrefix . $cField;
		}
		return $aLabel ;
	}
	function getDescription( $cValue  )
	{
		$aValue  = explode ( $this->cSeparator , trim($cValue) );
		$cReturn = ''; $nIndex = 0;
		foreach( $this->aInput as $oInput )
		{
			$cValue = $aValue[$nIndex++];
			if ( $cValue )
			{
				if ( get_class($oInput) == 'InputList' ) 
				{
					$cDescripcion =  $oInput->getDescription($cValue) ;
					$cReturn .= ( $cDescripcion ? $cDescripcion: $cValue) . ' '  ;
				}
				else
					$cReturn .= $cValue. ' '  ;
			}
		}
		return $cReturn ;
	}
	function setSeparator( $cSeparator )
		{
			$this->cSeparator = $cSeparator;
		}
	function setValueString( $cString )
		{
			$aValue  = $explode ( $this->cSeparator , $cString);
			$nIndex = 0;
			foreach( $this->aInput as $oInput )
			{
				$cValue = $aValue[$nIndex++];
				$oInput->setValue( $cValue );
			}
		}
	function getValueString()
		{
			$cReturn = '';
			foreach( $this->aInput as $oInput )
			{
				$cReturn .= $oInput->getValue ()  . $this->cSeparator ;
			}
			return $cReturn ;
		}
	function setHidden( $bOn = true)
	{
		foreach( $this->aInput as $oInput )
		{
			$oInput->setHidden($bOn);
		}
		$this->bHidden = $bOn;
	}
	// Debe tener el Modulo
	function setAutoRefresh( $cField, $oForm )
	{
		$this->bAutoRefresh = true;
		$cUrl = $oForm->getUrlAutoRefresh();
		$cUrl = replaceString( PARAM_REFRESH, "class",  $cUrl );
		$cUrl = replaceString( PARAM_METHOD, "refreshField",  $cUrl );
		$cUrl = replaceString( PARAM_FIELD, $this->cField ,  $cUrl );
		$this->aInput[$cField]->setOnChange ( "return send( \"$cUrl&$cField=\" + this.value, refreshElement, \"" . $this->cField . "\");" );
	}
	function make()    
	{
		$cReturn = "";
		//if ( $this->bAutoRefresh  ) 
		$cReturn = "<div id='" . $this->cField . "' style='display: inline'>";
		foreach( $this->aInput as $oInput )
		{
			if ( ! $oInput->isHidden() ) $cReturn .= $oInput->getLabel() . ' ';
			if ( !$this->bHidden )  $cReturn .= $oInput->make();
			if ( !$this->bHidden ) $cReturn .= $oInput->showActions();
		}
		//if ( $this->bAutoRefresh  ) 
		$cReturn .= "</div>";
		return $cReturn;
	}
	function addInput( &$oInput )
	{
		$this->aInput[$oInput->cField] = $oInput;
	}
	function getValue()
	{
		$aRet = array();
		foreach( $this->aInput as $cKey => $oInput )
		{
			$oRet = $oInput->getValue();
			if ( is_array( $oRet ) )
				$aRet = array_merge ( (array)$aRet ,  (array)$oRet );
			else
				$aRet[$cKey] = $oRet ;
		}
		return $aRet;
	}
}
?>